<template>
	<view>
		<view class="page">
			<comp-common v-bind="{data:data}" @getUserInfo="getUserInfo" @myLogin="myLogin" @getPhoneNumber="getPhoneNumber" @hideGetCoupon="hideGetCoupon" @closeCouponBox="closeCouponBox" @navigatorClick="navigatorClick"></comp-common>
			<comp-header v-bind="{data:data}" @relevanceError="relevanceError" @relevanceSuccess="relevanceSuccess"></comp-header>
			<view class="body after-navber" v-if="data.__user_info&&data.__user_info.is_distributor==1">
				<view class="info">
            <view class="info-title flex-row">
                <view class="flex-y-center">
                    <image class="info-img" :src="data.__user_info.avatar_url"></image>
                </view>
                <view class="info-block">
                    <view class="info-up info-blod">{{data.__user_info.nickname}}</view>
                    <view class="info-bottom">{{data.custom.words.parent_name.name}}：{{data.__user_info.parent}}</view>
                </view>
            </view>
            <view class="info-content flex-row">
                <view class="info-left">
                    <view class="info-label">
                        <view class="info-first">{{data.custom.words.can_be_presented.name}}</view>
                        <view class="info-second info-blod info-big flex-row">{{data.price}}元</view>
                    </view>
                </view>
                <view class="info-right">
                    <navigator class="" openType="navigate" url="/pages/cash/cash">
                        <view class="info-btn">{{data.custom.words.cash.name}}</view>
                    </navigator>
                </view>
            </view>
        </view>
        <view class="new-block flex-row">
            <view class="flex-grow-1 flex-x-center">
                <view class="text-more">
                    <view class="text-more" style="color:#22af19;margin-bottom: 16upx;">{{data.custom.words.already_presented.name}}</view>
                    <view class="text-more">{{data.cash_price}}元</view>
                </view>
            </view>
            <view class="flex-grow-1 flex-x-center">
                <view class="text-more">
                    <view class="text-more" style="color:#ff8f17;margin-bottom: 16upx;">{{data.custom.words.order_money_un.name}}</view>
                    <view class="text-more">{{data.order_money_un}}元</view>
                </view>
            </view>
        </view>
        <view class="list flex-row">
            <navigator class="item border-bottom" url="/pages/share-money/share-money">
                <view class="list-img flex-x-center">
                    <image class="img" :src="data.custom.menus.money.icon"></image>
                </view>
                <view class="list-content text-more">{{data.custom.menus.money.name}}</view>
                <view class="flex-x-center list-content">
                    <view class="list-red">{{data.total_price}}</view>元</view>
            </navigator>
            <navigator class="item border-bottom border-between" url="/pages/share-order/share-order">
                <view class="list-img flex-x-center">
                    <image class="img" :src="data.custom.menus.order.icon"></image>
                </view>
                <view class="list-content text-more">{{data.custom.menus.order.name}}</view>
                <view class="flex-x-center list-content">
                    <view class="list-red">{{data.order_money}}</view>元</view>
            </navigator>
            <navigator class="item border-bottom" url="/pages/cash-detail/cash-detail">
                <view class="list-img flex-x-center">
                    <image class="img" :src="data.custom.menus.cash.icon"></image>
                </view>
                <view class="list-content text-more">{{data.custom.menus.cash.name}}</view>
                <view class="flex-x-center list-content">
                    <view class="list-red">{{data.total_cash}}</view>元</view>
            </navigator>
        </view>
        <view class="list flex-row">
            <navigator class="item border-bottom" url="/pages/share-team/share-team" v-if="data.share_setting.level!=4">
                <view class="list-img flex-x-center">
                    <image class="img" :src="data.custom.menus.team.icon"></image>
                </view>
                <view class="list-content text-more">{{data.custom.menus.team.name}}</view>
                <view class="flex-x-center list-content">
                    <view class="list-red">{{data.team_count}}</view>人</view>
            </navigator>
            <navigator class="item border-bottom border-between" url="/pages/share-qrcode/share-qrcode">
                <view class="list-img flex-x-center">
                    <image class="img" :src="data.custom.menus.qrcode.icon"></image>
                </view>
                <view class="list-content text-more">{{data.custom.menus.qrcode.name}}</view>
            </navigator>
            <view class="item border-bottom" v-if="data.share_setting.level==4"></view>
            <view class="item border-bottom"></view>
        </view>
			</view>
			<view class="after-navber" style="background-color:#fff;height:100%" v-if="data.__user_info&&data.__user_info.is_distributor!=1">
        <view style="padding-top:150upx">
            <view class="flex-row flex-x-center">
                <view class="">
                    <image :src="data.__wxapp_img.share.tip.url" style="width:420upx;height:240upx;"></image>
                </view>
            </view>
            <view class="flex-row flex-x-center" style="padding:80upx 0 88upx 0;">您还不是{{data.custom.share_name.name?data.custom.share_name.name:'分销商'}}。请先提交申请！</view>
            <view class="felx-row flex-x-center">
                <form @submit="apply" reportSubmit="true">
                    <button class="flex-x-center flex-y-center" formType="submit" style="width:560upx;height:80upx;border-radius:40upx;background-color:#ff4544;color:#fff;">立即前往</button>
                </form>
            </view>
        </view>
    </view>
			<comp-footer v-bind="{data:data}"></comp-footer>
		</view>
	</view>
</template>

<script>var myVue = {};
	export default {
		data() {
			return {
				data: {
        total_price: 0,
        price: 0,
        cash_price: 0,
        total_cash: 0,
        team_count: 0,
        order_money: 0
    },
			};
		},
		onLoad: function(e) {myVue = this;
        myVue.getApp.page.onLoad(this, e), this.setData({
            custom: myVue.getApp.core.getStorageSync(myVue.getApp.const.CUSTOM)
        });
    },
    onReady: function() {
        myVue.getApp.page.onReady(this);
    },
    onShow: function() {
        myVue.getApp.page.onShow(this);
        var e = this, t = myVue.getApp.core.getStorageSync(myVue.getApp.const.SHARE_SETTING), o = e.data.__user_info;
        e.setData({
            share_setting: t
        }), o && 1 == o.is_distributor ? e.checkUser() : e.loadData();
    },
		onHide: function() {
        myVue.getApp.page.onHide(this);
    },
    onUnload: function() {
        myVue.getApp.page.onUnload(this);
    },
		methods: {
			checkUser: function() {
        var e = this;
        myVue.getApp.core.showLoading({
            title: "正在加载",
            mask: !0
        }), myVue.getApp.request({
            url: myVue.getApp.api.share.get_info,
            success: function(t) {
                0 == t.code && (e.setData({
                    total_price: t.data.price.total_price,
                    price: t.data.price.price,
                    cash_price: t.data.price.cash_price,
                    total_cash: t.data.price.total_cash,
                    team_count: t.data.team_count,
                    order_money: t.data.order_money,
                    custom: t.data.custom,
                    order_money_un: t.data.order_money_un
                }), e.getApp.core.setStorageSync(e.getApp.const.CUSTOM, t.data.custom), e.loadData()), 
                1 == t.code && (__user_info.is_distributor = t.data.is_distributor, e.setData({
                    __user_info: __user_info
                }), e.getApp.setUser(__user_info));
            },
            complete: function() {
                e.getApp.core.hideLoading();
            }
        });
    },
    loadData: function() {
        var e = this;
        myVue.getApp.core.showLoading({
            title: "正在加载",
            mask: !0
        }), myVue.getApp.request({
            url: myVue.getApp.api.share.index,
            success: function(t) {
                if (0 == t.code) {
                    if (t.data.share_setting) o = t.data.share_setting; else var o = t.data;
                    e.getApp.core.setStorageSync(e.getApp.const.SHARE_SETTING, o), e.setData({
                        share_setting: o
                    });
                }
            },
            complete: function() {
                e.getApp.core.hideLoading();
            }
        });
    },
		apply: function(e) {
        var t = this, o = myVue.getApp.core.getStorageSync(myVue.getApp.const.SHARE_SETTING), a = myVue.getApp.getUser();
        1 == o.share_condition ? myVue.getApp.core.navigateTo({
            url: "/pages/add-share/index"
        }) : 0 != o.share_condition && 2 != o.share_condition || (0 == a.is_distributor ? myVue.getApp.core.showModal({
            title: "申请成为" + (t.data.custom.share_name || "分销商"),
            content: "是否申请？",
            success: function(t) {
                t.confirm && (myVue.getApp.core.showLoading({
                    title: "正在加载",
                    mask: !0
                }), myVue.getApp.request({
                    url: myVue.getApp.api.share.join,
                    method: "POST",
                    data: {
                        form_id: e.detail.formId
                    },
                    success: function(e) {
                        0 == e.code && (0 == o.share_condition ? (a.is_distributor = 2, t.getApp.core.navigateTo({
                            url: "/pages/add-share/index"
                        })) : (a.is_distributor = 1, t.getApp.core.redirectTo({
                            url: "/pages/share/index"
                        })), t.getApp.setUser(a));
                    },
                    complete: function() {
                        t.getApp.core.hideLoading();
                    }
                }));
            }
        }) : myVue.getApp.core.navigateTo({
            url: "/pages/add-share/index"
        }));
    }
		},
	}
</script>

<style scoped>
.info {
    width: 100%;
    background-color: #ff4544;
    padding: 20upx 24upx 0 24upx;
    color: #fff;
}

.info .info-title {
    border-bottom: 1upx #ffa2a2 solid;
    padding-bottom: 20upx;
}

.info .info-title .info-img {
    width: 120upx;
    height: 120upx;
    border-radius: 120upx;
}

.info .info-block {
    padding: 18upx 40upx;
}

.info .info-block .info-up {
    font-size: 13pt;
    margin-bottom: 30upx;
}

.info-big {
    font-size: 13pt;
}

.info .info-content {
    width: 100%;
    padding-top: 22upx;
}

.info .info-content .info-left {
    width: 50%;
}

.info .info-content .info-right {
    width: 50%;
    margin-top: 24upx;
}

.info .info-content .info-left .info-label {
    padding-bottom: 40upx;
}

.info-label .info-first {
    margin-bottom: 24upx;
}

.info-right .info-btn {
    border: 1upx #e3e3e3 solid;
    border-radius: 10upx;
    float: right;
    text-align: center;
    font-size: 13pt;
    margin-bottom: 24upx;
    padding: 6upx;
}

.list {
    background-color: #fff;
    width: 100%;
}

.list .border-bottom {
    border-bottom: 1upx #e3e3e3 solid;
}

.list .item {
    width: 33.3333%;
    height: 220upx;
    border-right: 1upx solid #e3e3e3;
}

.list .item:last-child {
    border-right: 0;
}

.list .item .list-img {
    width: 100%;
    margin-top: 40upx;
    text-align: center;
}

.list .item .list-img .img {
    width: 50upx;
    height: 50upx;
}

.list .item .list-content {
    color: #666;
    margin-top: 13upx;
    text-align: center;
}

.list-red {
    color: #ff4544;
}

.new-block {
    width: 100%;
    padding: 44upx 10upx;
    margin-bottom: 16upx;
    background-color: #fff;
}

.new-block .flex-grow-1 {
    width: 50%;
}

.new-block .flex-grow-1:first-child {
    border-right: 1upx #eee solid;
}

.new-block .flex-grow-1 {
    text-align: center;
}
</style>
